<template>
  <div class="container">
    <div class="header">
      <van-nav-bar title="养殖状态" left-text="返回" right-text left-arrow @click-left="onClickLeft"/>
    </div>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div class="animal_info">
        <ul class="top">
          <li>
            <img :src="imgUrl" alt>
          </li>
          <li>{{productName}}</li>
        </ul>
        <ul class="bottom">
          <li v-for="(item,index) in attr" :key="index">{{item.spec_name}}：{{item.spec_value_name}}</li>
        </ul>
      </div>
      <div class="timeLine">
        <ul class="cbp_tmtimeline">
          <li v-for="(item,index) in stateList" :key="index">
            <span class="circle"></span>
            <time class="cbp_tmtime" datetime="2013-04-10 18:30">
              <div v-for="(at,eq) in item.timeList" :key="eq">{{at}}</div>
            </time>
            <div class="cbp_tmlabe cbp_img">
              <img :src="item.product_image_url" alt>
              <h5>{{item.presentation}}</h5>
            </div>
          </li>
        </ul>
      </div>
    </van-pull-refresh>
  </div>
</template>
<script>
export default {
  name: "farmingState",
  data() {
    return {
      //下拉刷新
      isLoading: false,
      imgUrl: "",
      productName: "",
      stateList: [],
      attr: []
    };
  },
  mounted() {
     let u = navigator.userAgent;
            let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
            let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
            let message={
                orderId:this.orderId,
                formData:this.formData
            }

      if (isAndroid) {
      } else if (isiOS) {
         window.webkit.messageHandlers.goBackLogin.postMessage(null);
      }
    if (this.$route.query.imgUrl) {
      this.imgUrl = this.$route.query.imgUrl;
    }
    if (this.$route.query.product_name) {
      this.productName = this.$route.query.product_name;
    }
    this.adoptState();
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    //获取养殖状态数据数据
    async adoptState() {
      let params = {
        farmInfoId: this.$route.query.farmInfoId
      };
      const res = await this.$axios.post(this.$api.myFramState, params);
      if (res.success) {
        this.stateList = res.data;
        this.stateList.forEach((item, index) => {
          item.timeList = item.create_date.split(" ");
          item.goods_spec_format = JSON.parse(item.goods_spec_format);
          item.goods_spec_format.forEach((at, eq) => {
            at.spec_value_name = at.value[0].spec_value_name;
          });
        });
        this.attr = this.stateList[0].goods_spec_format;
        this.isLoading = false;
        // console.log(this.stateList);
      } else {
        this.$toast(res.msg);
      }
    },
    //下拉刷新
    onRefresh() {
      this.adoptState();
    }
  }
};
</script>
<style scoped>
@import "../assets/css/farmingState.css";
.container {
  padding-top: 0.46rem;
}
.header {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
}
.timeLine {
  width: 94%;
  margin: 52px auto;
}
.cbp_tmtimeline {
  margin: 30px 0 0 0;
  padding: 0;
  list-style: none;
  position: relative;
}
.cbp_tmtimeline > li:before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ccc;
  left: 32%;
  margin-left: -10px;
}
.cbp_tmtimeline > li:last-child:before {
  width: 0;
}
.cbp_tmtimeline > li {
  position: relative;
  margin: 0;
  padding: 0;
  display: inline-block;
  width: 100%;
}
.cbp_tmtimeline > li .cbp_tmtime {
  display: block;
  width: 28%;
  position: absolute;
  color: #333;
  font-size: 1.2em;
  font-weight: 500;
}
.cbp_tmtimeline > li .circle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ccc;
  display: block;
  position: absolute;
  left: 32%;
  margin-left: -14px;
  z-index: 2;
  top: -4px;
}
.cbp_tmtimeline > li .circle:hover {
  background: #06d039;
}
.cbp_tmtimeline > li:after {
  content: "";
  position: absolute;
  height: 2px;
  background: #ccc;
  left: 32%;
  margin-left: -10px;
  width: 50%;
  top: 0;
  z-index: 1;
}
.cbp_tmtimeline > li .cbp_tmlabel {
  margin: 0 0 15px 35%;
  background: #fff;
  color: #333;
  padding: 12px 15px;
  font-size: 1.4em;
  font-weight: 300;
  line-height: 1.4;
  position: relative;
  border-radius: 10px;
  box-sizing: border-box;
  top: -40px;
  z-index: 3;
}
.cbp_tmtimeline > li .cbp_img {
  margin: 0 0 15px 35%;
  background: #fff;
  color: #333;
  font-size: 1.4em;
  font-weight: 300;
  line-height: 1.4;
  position: relative;
  border-radius: 10px;
  box-sizing: border-box;
  top: -40px;
  z-index: 3;
  overflow: hidden;
}
.cbp_tmtimeline > li .cbp_img img {
  width: 100%;
  height: auto;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.cbp_tmtimeline > li .cbp_img h5 {
  padding: 12px 15px;
}
</style>
